<template>
  <div>
    <!-- 新增修改表单 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="DialogFormVisibleCom">
      <el-form ref="dataForm" :model="formSubmitDataCom" :rules="rules" label-position="right" label-width="100px"
               style="width: 90%; margin:10px auto;">

        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 法人代码 -->
            <el-form-item label="法人代码：" prop="lp_code">
              <el-input v-model="formSubmitDataCom.lp_code" v-bind:disabled="this.formSubmitDataCom.id !=''"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 法人名称 -->
            <el-form-item label="法人名称：" prop="lp_name">
              <el-input v-model="formSubmitDataCom.lp_name"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 注册日期 -->
            <el-form-item label="注册日期：" prop="rg_date">
              <el-date-picker
                v-model="formSubmitDataCom.rg_date"
                placeholder="Please pick a date"
                type="date"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 注册金额 -->
            <el-form-item label="注册金额：" prop="rg_amt">
              <el-input v-model="formSubmitDataCom.rg_amt"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 员工编号 -->
            <el-form-item label="员工编号：" prop="us_code">
              <el-input v-model="formSubmitDataCom.us_code"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 员工姓名 -->
            <el-form-item label="员工姓名：" prop="us_name">
              <el-input v-model="formSubmitDataCom.us_name"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 实体机构 -->
            <el-form-item label="实体机构：" prop="branch_code">
              <el-cascader
                v-model="formSubmitDataCom.branch_code"
                :options="legalQueryBranchOptions"
                :props="{ emitPath: false ,checkStrictly: true}"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <!-- 备注 -->
            <el-form-item label="备注：" prop="remark">
              <el-input v-model="formSubmitDataCom.remark" placeholder="Please select" type="textarea"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// import PageHeaderLayout from '@/layouts/PageHeaderLayout'
// import ApeDrawer from '@/components/ApeDrawer'
// import { mapGetters } from 'vuex'
const calendarTypeOptions = [
  {key: 'CN', display_name: 'China'},
  {key: 'US', display_name: 'USA'},
  {key: 'JP', display_name: 'Japan'},
  {key: 'EU', display_name: 'Eurozone'}
]

// arr to obj, such as { CN : "China", US : "USA" }
const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})


export default {
  name: 'submitForm',
  components: {
    //PageHeaderLayout,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
  
    formSubmitData: {
      type: Object,
      default: function () {
        return {
          id: '',
          lp_code: '', //法人代码
          lp_name: '', //法人名称
          rg_date: '', //注册日期
          rg_amt: '', //注册金额
          us_code: '', //员工编号
          us_name: '', //员工姓名
          branch_code: '', //实体机构
          status: '1', //状态
          remark: '', //备注
        }
      }
    },
    legalQueryBranchOptions: {
      type: Array,
    }
  },

  // 定义属性
  data() {
    return {
      textMap: {
        update: '修改',
        create: '新增'
      },
      rules: {
        lp_code: [{required: true, message: '法人代码必填', trigger: 'change'}],
        lp_name: [{required: true, message: '法人名称必填', trigger: 'change'}],
        branch_code: [{required: true, message: '实体机构必填', trigger: 'change'}],
        status: [{required: true, message: '状态必填', trigger: 'change'}],
      
      },
      // 表单用到的值
      calendarTypeOptions,
     
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    }
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    resetFormData() {
      this.$emit('resetFormDataEmit')
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromCreateDataEmit')

        }
      })
    },

    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$delete(this.formSubmitDataCom, "_XID");
          this.$delete(this.formSubmitDataCom, "branch_name");
          const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')

        }
      })
    },

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>

</style>